﻿using UnityEditor;
using UnityEngine;
using UnityToolbarExtender;

namespace XProject
{
    static class ToolbarStyles
    {
        public static readonly GUIStyle commandButtonStyle;

        static ToolbarStyles()
        {
            commandButtonStyle = new GUIStyle("Command")
            {
                fontSize = 12,
                alignment = TextAnchor.MiddleCenter,
                imagePosition = ImagePosition.ImageAbove,
                fixedWidth = 100,
            };
        }
    }

    [InitializeOnLoad]
    public class SwitchLoad
    {
        static SwitchLoad()
        {
            ToolbarExtender.RightToolbarGUI.Add(OnToolbarGUI);
        }

        static void OnToolbarGUI()
        {
            if (!Application.isPlaying)
            {
                GUILayout.FlexibleSpace();

                if (GUILayout.Button(new GUIContent("切换资源加载模式", "点一下切换"), ToolbarStyles.commandButtonStyle))
                {
                    if (XEditorConfig.GetInstance().IsABAssetLoadMode)
                    {
                        XEditorConfig.GetInstance().IsABAssetLoadMode = false;
                        Debug.Log("关闭ab加载模式");
                    }
                    else
                    {
                        XEditorConfig.GetInstance().IsABAssetLoadMode = true;
                        Debug.Log("开启ab加载模式,记得先构建一次ab资源");
                    }
                }
            }
        }
    }


}